package com.app.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
public class Basedao {	
	   public void insert( String sql, Object[] params) throws SQLException{
			Connection conn = null;
		    QueryRunner qr =null;
			try{	
		         conn = DriverManager.getConnection("proxool.yjxt");
		         qr = new QueryRunner();
		     //    qr.query(conn, sql, new BeanHandler<T>())
		         qr.update(conn, sql,params);
		         
			}finally{
				if (conn!=null)
				  conn.close();	
			} 
	   }
	   @SuppressWarnings("unchecked")
	public  int getint( String sql, Object[] params) throws SQLException{
		   Connection conn = null;
		    QueryRunner qr =null;
		    int i=0;
			try{
		          conn = DriverManager.getConnection("proxool.yjxt");
		          qr = new QueryRunner();
		           i=((Number) qr.query(conn,sql,new ScalarHandler(1),params)).intValue();         
			}finally{
				if (conn!=null)
				  conn.close();	
			}
			return i;		
		}
	   public static void main(String[] args) {	
			System.out.println("11111111");
		}
	   
	   public   Object getBean(String sql, Object[] params,Class c) throws SQLException{
		    Connection conn = null;
		    QueryRunner qr =null;
			try{
		          conn = DriverManager.getConnection("proxool.yjxt");
		          qr = new QueryRunner();
				  Object obj =qr.query(conn, sql, params,new BeanHandler(c))   ;  
		       	  return obj;  
			}finally{
				if (conn!=null)
				  conn.close();	
			}
		   
	
		   
		   
	   }
  }
